#include "stdafx.h"
#include "FAFlow.h"

CFAFlow::CFAFlow()
{
	m_pThreadQuery = new CYKThread(FlowQuery, this,0);
	m_pThreadOrder = new CYKThread(FlowOrder, this, 0);
}

void *CFAFlow::FlowQuery(const bool *stop, void *param)
{
	CFAFlow * p = (CFAFlow*)param;

	while (!(*stop))
	{
		CTask * obj = 0;
		if (0 == p->m_vQueryTask.get(obj, QUERY_FLOW_SLEEP))
		{
			if (obj->mtype == FLOW_EXIT)
			{
				break;
			}

			obj->mpHandle->Handle();
			obj->mpHandle->Uninit();
			SAFE_DEL(obj->mpHandle);
			SAFE_DEL(obj);
		}

		//Sleep(QUERY_FLOW_SLEEP);
	}

	return 0;
}


void *CFAFlow::FlowOrder(const bool *stop, void *param)
{
	CFAFlow * p = (CFAFlow*)param;

	while (!(*stop))
	{
		CTask* obj;
		if (0 == p->m_vOrderTask.get(obj, ORDER_FLOW_SLEEP))
		{
			if (obj->mtype == FLOW_EXIT)
			{
				break;
			}

			obj->mpHandle->Handle();
			obj->mpHandle->Uninit();
			SAFE_DEL(obj->mpHandle);
			SAFE_DEL(obj);

		}

		//Sleep(ORDER_FLOW_SLEEP);
	}

	return 0;
}

void CFAFlow::RegisterQueryTask(CTask*pTask)
{
	m_vQueryTask.put(pTask);
}

void CFAFlow::RegisterOrderTask(CTask*pTask)
{
	m_vOrderTask.put(pTask);
}


void CFAFlow::Start()
{
	m_pThreadQuery->start();
	m_pThreadOrder->start();
}

void CFAFlow::Stop()
{
	m_pThreadQuery->stop();
	m_pThreadOrder->stop();
}